<?php
class UserPermissionPreferencesController extends AppController
{
    public $name = 'UserPermissionPreferences';
    public function edit()
    {
        $user_id = $this->Auth->user('id');
        $this->pageTitle = __l('Edit Notification Settings');
        if (!empty($this->request->data)) {
            if (empty($this->request->data['UserPermissionPreference']['user_id'])) {
                $this->request->data['UserPermissionPreference']['user_id'] = $this->Auth->user('id');
            }
            if ($this->UserPermissionPreference->save($this->request->data)) {
                $this->Session->setFlash(__l('Permissions are updated') , 'default', null, 'success');
            } else {
                $this->Session->setFlash(__l('Permissions could not be updated. Please, try again.') , 'default', null, 'error');
            }
        }
        $this->request->data = $this->UserPermissionPreference->find('first', array(
            'conditions' => array(
                'UserPermissionPreference.user_id' => $user_id
            )
        ));
        $this->request->data['User']['username'] = $this->request->data['User']['username'] ? $this->request->data['User']['username'] : $this->Auth->user('username');
        $this->pageTitle.= ' - ' . $this->request->data['User']['username'];
        $this->request->data['UserPermissionPreference']['user_id'] = $user_id;
    }
    public function admin_edit($user_id)
    {
        $this->setAction('edit', $user_id);
    }
}
?>